<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="lianxi3.css">
</head>

<body>
    <div class="box">
        <h2>注册</h2>
        <div class="center ">
            <p>手机号：</p>
            <input type="text" placeholder="请输入手机号" class="i1 i2">
            <p>密码：</p>
            <input type="text" placeholder="设置登录密码，不少于8位" class="i1 i3">
        </div>
        <di v class=" zhuce active">
            <p>验证码：</p>
            <input type="text" placeholder="请输入验证码" class="i1 yanzhengma">
            <p>昵称：</p>
            <input type="text" placeholder="昵称" class="i1 nicheng">
        </div>
        <button class="btn" style="margin-top: 156px; margin-left: 170px;">下一步</button>

        <div id="bottom1">
            <span style="margin-left: 20px;" class="s1"> <a href="登录练习.html">
                    < &nbsp;返回登录</a></span>
        </div>
    </div>
    <script>
        var btn = document.querySelector(".btn")
        var center = document.getElementsByClassName("center")[0]
        var zhuce = document.getElementsByClassName("zhuce")[0]
        var count=0 
        btn.addEventListener("click", function () {
            count=count+1
            console.log(count)
            var phone = document.getElementsByClassName("i2")[0].value*1
            var psw = document.getElementsByClassName("i3")[0].value
            center.classList.add("active")
            zhuce.classList.remove("active")
            var ma = document.getElementsByClassName("yanzhengma")[0].value*1
            var nicheng = document.getElementsByClassName("nicheng")[0].value
         
          //获取验证码
            if(count==1){
              
                var xhr=new XMLHttpRequest()
                xhr.open("POST","https://autumnfish.cn/captcha/sent")
                var data=`phone=${phone}`
                xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
                xhr.send(data)
                console.log(phone)
                console.log(psw)
                xhr.onreadystatechange=function(){
                    if(xhr.readyState===4&&xhr.status==200){
                        console.log(xhr.responseText)
                        console.log("11111111111")
                    }
                }
            }
        //注册
            if(count==2){
                var xhr=new XMLHttpRequest()
                xhr.open("POST","https://autumnfish.cn//register/cellphone")
                var data=`phone=${phone}&password=${psw}&captcha=${ma}&nickname=${nicheng}`
                xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
                xhr.send(data)
                xhr.onreadystatechange=function(){
                    if(xhr.readyState===4&&xhr.status==200){
                        console.log(xhr.responseText)
                        alert("zbbcibzibbj")
                    }
                } 
            }
    
        })
        
    </script>
</body>

</html>